{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0249ddad-6968-4e9e-aa9c-2141c9296df7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<generator object <genexpr> at 0x0000022070D36BA0>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g = (x *x  for x in range(10))\n",
    "g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8e77e9b9-bb58-4095-88eb-1cf9a158fc74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next(g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "23517f7c-1352-4e47-90d1-ff207690b1d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next(g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c4516e7c-81b5-444b-8663-9b44de2ea368",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next(g) \n",
    "next(g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b8fefab8-07e1-407a-9cbe-9c36099faf9f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next(g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "eb51d4a1-cd75-4209-9059-e74d7732b1ef",
   "metadata": {},
   "outputs": [
    {
     "ename": "StopIteration",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mStopIteration\u001b[0m                             Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[8], line 6\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28mnext\u001b[39m(g) \n\u001b[0;32m      5\u001b[0m \u001b[38;5;28mnext\u001b[39m(g) \n\u001b[1;32m----> 6\u001b[0m \u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mg\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[1;31mStopIteration\u001b[0m: "
     ]
    }
   ],
   "source": [
    "next(g) \n",
    "next(g)\n",
    "next(g) \n",
    "next(g) \n",
    "next(g) \n",
    "next(g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a39ebaec-33ca-4abc-8223-59f569f2eda2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "4\n",
      "9\n",
      "16\n",
      "25\n",
      "36\n",
      "49\n",
      "64\n",
      "81\n"
     ]
    }
   ],
   "source": [
    "g = (x *x  for x in range(10))\n",
    "for n in g: \n",
    "    print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "90e877f6-f266-4971-93ff-f970349f2882",
   "metadata": {},
   "outputs": [],
   "source": [
    "def odd():\n",
    "    print('step 1')\n",
    "    yield 1\n",
    "    print('step 2')\n",
    "    yield 2\n",
    "    print('step 3')\n",
    "    yield 3\n",
    "    print('step 5')\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "df8ef1e9-14e0-4ccc-ad5b-3d8e6d6316f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "o = odd() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0e1b1699-8b77-49f8-8774-2d6e7fa76bea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "step 1\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next(o)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "024839a9-8f24-4c8c-8d79-06171623acd8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "step 2\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "next(o)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "09d089d7-0814-45b8-a153-62f94e529660",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "step 3\n",
      "3\n",
      "step 5\n"
     ]
    }
   ],
   "source": [
    "for n in o: \n",
    "    print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f58f7fed-54e7-4c48-8f76-67f95f9a6b0b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
